/*
 * AboutBox.java
 *
 * Copyright(c) 2010 - Kimnach
 * See main.Main.java for full copyright notice.
 *
 */

package gui;

import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 * Displays version, credits, software info
 * @author dkimnach
 */
public class AboutBox extends javax.swing.JDialog {

    /**
     * Constructor for AboutBox
     * @param parent
     */
    public AboutBox(java.awt.Frame parent) {
        super(parent);
        initComponents();
        getRootPane().setDefaultButton(closeButton);
        setupLink(lblGameURL, "http://www.smirkanddagger.com/cutthroat.htm");
        setupLink(lblProjectURL, "http://code.google.com/p/cc-toolbox/");
    }

    /**
     * Closes AboutBox
     */
    @Action public void closeAboutBox() {
        dispose();
    }
    
    // opens clicked urls
    private void open(URI uri) {
        if (Desktop.isDesktopSupported()) {
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(uri);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(null,
                    "Failed to launch the link, " +
                    "your computer is likely misconfigured.",
                    "Cannot Launch Link",JOptionPane.WARNING_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(null,
                "Java is not able to launch links on your computer.",
                "Cannot Launch Link",JOptionPane.WARNING_MESSAGE);
        }
    }
    
    // sets mouse listener to open urls
    private void setupLink(JLabel label, String text) {
        final URI uri;
        try {
            uri = new URI(text);
            label.setToolTipText(uri.toString());
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    open(uri);
                }
            });
        } catch (URISyntaxException ex) {
            throw new RuntimeException(ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        closeButton = new javax.swing.JButton();
        javax.swing.JLabel appTitleLabel1 = new javax.swing.JLabel();
        javax.swing.JLabel versionLabel1 = new javax.swing.JLabel();
        javax.swing.JLabel vendorLabel1 = new javax.swing.JLabel();
        javax.swing.JLabel appVendorLabel2 = new javax.swing.JLabel();
        lblProjectURL = new javax.swing.JLabel();
        javax.swing.JLabel vendorLabel2 = new javax.swing.JLabel();
        javax.swing.JLabel appVendorLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel vendorLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel appVendorLabel4 = new javax.swing.JLabel();
        lblGameURL = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(AboutBox.class);
        setTitle(resourceMap.getString("aboutBox.title")); // NOI18N
        setModal(true);
        setName("aboutBox"); // NOI18N
        setResizable(false);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(AboutBox.class, this);
        closeButton.setAction(actionMap.get("closeAboutBox")); // NOI18N
        closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N
        closeButton.setName("closeButton"); // NOI18N

        appTitleLabel1.setFont(appTitleLabel1.getFont().deriveFont(appTitleLabel1.getFont().getStyle() | java.awt.Font.BOLD, appTitleLabel1.getFont().getSize()+4));
        appTitleLabel1.setText(resourceMap.getString("appTitleLabel1.text")); // NOI18N
        appTitleLabel1.setName("appTitleLabel1"); // NOI18N

        versionLabel1.setFont(versionLabel1.getFont().deriveFont(versionLabel1.getFont().getStyle() | java.awt.Font.BOLD));
        versionLabel1.setText(resourceMap.getString("versionLabel1.text")); // NOI18N
        versionLabel1.setName("versionLabel1"); // NOI18N

        vendorLabel1.setFont(vendorLabel1.getFont().deriveFont(vendorLabel1.getFont().getStyle() | java.awt.Font.BOLD));
        vendorLabel1.setText(resourceMap.getString("vendorLabel1.text")); // NOI18N
        vendorLabel1.setName("vendorLabel1"); // NOI18N

        appVendorLabel2.setText(resourceMap.getString("appVendorLabel2.text")); // NOI18N
        appVendorLabel2.setName("appVendorLabel2"); // NOI18N

        lblProjectURL.setText(resourceMap.getString("lblProjectURL.text")); // NOI18N
        lblProjectURL.setName("lblProjectURL"); // NOI18N

        vendorLabel2.setFont(vendorLabel2.getFont().deriveFont(vendorLabel2.getFont().getStyle() | java.awt.Font.BOLD));
        vendorLabel2.setText(resourceMap.getString("vendorLabel2.text")); // NOI18N
        vendorLabel2.setName("vendorLabel2"); // NOI18N

        appVendorLabel3.setText(resourceMap.getString("appVendorLabel3.text")); // NOI18N
        appVendorLabel3.setName("appVendorLabel3"); // NOI18N

        vendorLabel3.setFont(vendorLabel3.getFont().deriveFont(vendorLabel3.getFont().getStyle() | java.awt.Font.BOLD));
        vendorLabel3.setText(resourceMap.getString("vendorLabel3.text")); // NOI18N
        vendorLabel3.setName("vendorLabel3"); // NOI18N

        appVendorLabel4.setText(resourceMap.getString("appVendorLabel4.text")); // NOI18N
        appVendorLabel4.setName("appVendorLabel4"); // NOI18N

        lblGameURL.setText(resourceMap.getString("lblGameURL.text")); // NOI18N
        lblGameURL.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        lblGameURL.setName("lblGameURL"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(appTitleLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblProjectURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(153, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(versionLabel1)
                        .addGap(70, 70, 70)
                        .addComponent(appVendorLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
                        .addGap(107, 107, 107))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(vendorLabel1)
                            .addComponent(vendorLabel2))
                        .addGap(50, 50, 50)
                        .addComponent(appVendorLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(167, 167, 167))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblGameURL, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(vendorLabel3)
                                .addGap(15, 15, 15)
                                .addComponent(appVendorLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(closeButton)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(appTitleLabel1)
                        .addComponent(lblProjectURL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(versionLabel1)
                            .addComponent(appVendorLabel2))
                        .addGap(3, 3, 3)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(vendorLabel1)
                            .addComponent(vendorLabel2)
                            .addComponent(appVendorLabel3))
                        .addGap(3, 3, 3)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(vendorLabel3)
                            .addComponent(appVendorLabel4))
                        .addGap(13, 13, 13)
                        .addComponent(lblGameURL, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JLabel lblGameURL;
    private javax.swing.JLabel lblProjectURL;
    // End of variables declaration//GEN-END:variables

}